<?php
class UserBase extends Zend_Db_Table
{
	protected $_name = "userbase";
	
	function getAllUsers()
	{
		$select = $this->_db->select()
							->from(array('userBase'=>$this->_name),array('name'))
							->join(array('propertyEntry'=>'propertyentry'),
												'userBase.id = propertyEntry.entry_id',
														array('property_key'))
							->join(array('propertyString'=>'propertystring'),
												'propertyEntry.id = propertyString.id',
														array('propertyvalue'));
		$results = $this->getAdapter()->fetchAll($select);
		return $results;
	}
	
	function getUserById($id) 
	{
		$select = $this->_db->select()
							->from(array('userBase'=>$this->_name),array('id as uid','name'))
							->join(array('propertyEntry'=>'propertyentry'),
												'userBase.id = propertyEntry.entry_id',
																	array("property_key"))
							->join(array('propertyString'=>'propertystring'),
												'propertyEntry.id = propertyString.id',
														array('propertyvalue'))
							->where("userBase.id =?",$id);
		$results = $this->getAdapter()->fetchAll($select);
		return $results;
	}
	
	function getUsersList()
	{
		$select = $this->_db->select()
							->from(array('userBase'=>$this->_name),null)
							->join(array('propertyEntry'=>'propertyentry'),
												'userBase.id = propertyEntry.entry_id',
														array('property_key'))
							->join(array('propertyString'=>'propertystring'),
												'propertyEntry.id = propertyString.id',
														array('key'=>'propertyvalue','value' => 'propertyvalue'))
							->join(array('membershipBase'=>'membershipbase'), 'userBase.name = membershipBase.user_name')
							->where('group_name=?', 'ppmis-developers')
							->where('propertyEntry.property_key = ?','fullname');
		$results = $this->getAdapter()->fetchAll($select);
		return $results;
	}
	
	function getUserByFullname($fullname)
	{
		$select = $this->_db->select()
							->from(array('userBase'=>$this->_name),'id')
							->join(array('propertyEntry'=>'propertyentry'),
												'userBase.id = propertyEntry.entry_id',
														array('property_key'),null)
							->join(array('propertyString'=>'propertystring'),
												'propertyEntry.id = propertyString.id',
														null)
							->where('propertyEntry.property_key = ?','fullname')
							->where('propertyString.propertyvalue = ?', $fullname);
		$results = $this->getAdapter()->fetchOne($select);
		return $results;
	}
}